<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!--只在模块名下面有效 -->
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拜访记录统计</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
.visit_rec_detail_win {
	text-align: left !important;
	padding: 10px 25px 25px 25px;
}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div id="pageInTab" class="pageInTab">
				<div tabid="tabA" title="拜访记录统计" lselected="true">

					<div id="ligergridDB" class="sq-grid"></div>

					<!-- 附件展示 -->
					<ul id="dowebok" style="display:none">
					</ul>

				</div>
			</div>
		</div>
	</div>

	<script type="text/javascript">
		var gridDB = null;
		var pageInApp = {}; // to 下一级子窗口 接口
		var queryFlag = '${queryFlag}'; //只查询列表
		var pageInTab = null;
		var loadedTabs = [];
		var visitMessage = $('#visitMessage');
		var visitRecTotal;
		$(function() {
			initTab();
			initGridDB(); //初始化待办列表
			initOrgTree();
			$("#searchBar").ligerForm();
			$("#searchBtn").click(function(event) {
				reloadGrid();
			});
			$('#closeAttachmentsView').click(function() {
				closeAttachmentsView();
			});
		});
	
		//重新加载GRID
		function reloadGrid() {
			var form = new liger.get("searchBar");
			var data = form.getData();
			for (name in data) {
				console.log('name:' + name + ',data:' + data[name]);
				gridDB.setParm(name, data[name]);
			}
			;
			gridDB.reload();
		}
	
		//初始化列表
		function initGridDB() {
			$("#ligergridDB").ligerGrid({
				url : '<%=path%>/spl/splvisitrec/initList.do?crtUsrNm=' + '${cstManagerNm}' + '&isDel=0&isValid=1',
				method : 'get',
				columns : [
					{
						display : '经销商名称',
						name : 'splNm',
						width : 80,
						enabledSort : false
					},
					{
						display : '地址',
						name : 'visitPositAddr',
						minWidth : 100,
						enabledSort : false
					},
					{
						display : '城市',
						name : 'splRgnNm',
						minWidth : 100,
						enabledSort : false
					},
					{
						display : '联系人',
						name : 'conUsrNm',
						minWidth : 150,
						enabledSort : false,
						render : function(rowdata, index, value) {
							return value + "(" + rowdata.conTypCd + ")";
						}
					},
					{
						display : '是否关键决策人',
						name : 'isRelDecision',
						minWidth : 100,
						enabledSort : false,
						render : function(rowdata, index, value) {
							if (value == 1) {
								return "是";
							}
							if (value == 0) {
								return "否";
							}
						}
					},
					{
						display : '拜访目的',
						name : 'visitPurpCd',
						minWidth : 80,
						enabledSort : false
					},
	
					{
						display : '拜访时间',
						name : 'crtTm',
						minWidth : 120,
						enabledSort : false,
						render : function(rowdata, index, value) {
							return renderDate2(rowdata, index, value)
						}
					},
					{
						display : '负责人',
						name : 'crtUsrNm',
						minWidth : 30,
						enabledSort : false
					},
					/* {
						display : '事业部',
						name : 'buOrgCd',
						minWidth : 100,
						enabledSort : false
					},  */
					{
						display : '分公司',
						name : 'curOrgCd',
						minWidth : 100,
						enabledSort : false
					},
					{
						display : '签到距离',
						name : 'signInDis',
						minWidth : 30,
						enabledSort : false,
						render : function(rowdata, index, value) {
							if (value == 0) {
								return '0m';
							}
							if (value != null && value != '') {
								return value + 'm';
							}
						}
					},
					{
						display : '状态',
						name : 'isValid',
						minWidth : 50,
						enabledSort : false,
						render : function(rowdata, rowindex, value) {
							if (rowdata.isValid == 1 && rowdata.isDel == 0) {
								return "有效";
							}
							if (rowdata.isValid == 0 && rowdata.isDel == 0) {
								return "审核中";
							}
							if (rowdata.isDel == 1) {
								return "无效";
							}
						}
					},
					{
						display : '拜访结果',
						name : 'isSuccess',
						minWidth : 50,
						enabledSort : false,
						render : function(rowdata, rowindex, value) {
							if (value == 1) {
								return "成功";
							}
							if (value == 0) {
								return "失败";
							}
						}
					},
					{
						display : '操作',
						name : '',
						minWidth : 200,
						enabledSort : false,
						render : function(rowdata, rowindex, value) {
							//console.log(rowdata.visitDetail);
							var visitDetail;
							var h1;
							if (rowdata.visitDetail != null && rowdata.visitDetail != '') {
								visitDetail = rowdata.visitDetail;
								visitDetail = visitDetail.replace(/[\r\n]/g, "<br>");
								h1 = '<span onclick="getVisitMessage(\'' + visitDetail + '\')" title="' + visitDetail + '"><a class="sq-button-hasicon" href="javascript:;">拜访详情</a></span>';
							} else {
								visitDetail = '';
								h1 = '<span style="text-decoration:line-through"><a class="sq-button-hasicon">拜访详情</a></span>'
							}
							//console.log(visitDetail);
							var _id = rowdata.id;
							//var h1 = '<a class="sq-button-hasicon" onmouseover="getVisitMessage(\'' + visitDetail + '\');" onmouseout="closeVisitMessage()" href="javascript:;">拜访详情</a>';
							var h2 = '<a class="sq-button-hasicon" href="javascript:viewAttachments(' + rowdata.id + ')">查看附件</a>';
							return h1 + h2;
						}
					}
				],
				pageSize : 10,
				pageSizeOptions : [ 10, 20, 30, 40, 50, 100 ], //按照自己的喜好选择不同的页面显示条数
				root : 'rows',
				record : 'total',
				hideLoadButton : true,
				width : '100%',
				height : '100%',
				heightDiff : -30,
				//checkbox : true,
				rownumbers : true,
				onAfterShowData : function() {
					$(".gridTip").grid_ligerTip();
					SetIframe_height();
				},
				onLoaded : function (grid) {
					console.log(grid);
					grid.toggleLoading(null);
					console.log(grid.data.total);
					if (null == visitRecTotal) {
						visitRecTotal = grid.data.total;
					}
				}
			});
			gridDB = liger.get("ligergridDB");
			gridDB.setHeight(100);
			gridDB.options.isSingleCheck = true;
		}
	
		<!-- 查看拜访详情 -->
		function getVisitMessage(visitDetail, event) {
			$.ligerDialog.SQalert({
				SQ_showButtons : true,
				SQ_onBtnclick : function(item, Dialog) {
				},
				width : 500,
				//contentCls: 'visit_rec_detail_win', 
				content : visitDetail
			});
		}
	
		<!-- 查看附件 -->
		function viewAttachments(_id) {
			var urlArray = null;
			//alert(_id);
			$.ajax({
				type : 'get',
				dataType : 'json',
				data : {
					id : _id
				},
				url : '<%=path%>/spl/splvisitrec/viewAttachments.do',
				beforeSend : function() {
					wait_dialog = $.ligerDialog.SQalert({
						content : '正在查询附件...',
						SQ_type : "waitting"
					});
				},
				success : function(msg) {
					wait_dialog.close();
					if (msg.success == 1) {
						//console.log(msg.data);
						urlArray = msg.data;
						if (urlArray != null) {
							for (img in urlArray) {
								//console.log(urlArray[img]);
								var li = '<li><img  src="' + urlArray[img] + '" alt=""></li>';
								$('#dowebok').append(li);
							}
							//$('#dowebok').viewer();
							var viewer = new Viewer(document.getElementById('dowebok'), {
								hidden : function() {
									//alert('hidden');
									urlArray = null;
									$('#dowebok').html('');
									viewer.destroy();
								},
							});
							viewer.show();
						} else {
							$.ligerDialog.SQalert({
								content : '该记录没有附件...',
								SQ_type : "warn"
							});
						}
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				}
			});
		}
	
		//格式化时间
		function renderDate2(rowdata, index, value) {
			var dateStr = "";
			if (null != value) {
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
			}
			return dateStr;
		}
	
		function iframeResize() {
			if (parent.mainApp) {
				parent.mainApp.parentTab.onResize();
			}
			;
		}
	
		//初始化Tab页
		function initTab() {
			pageInTab = $("#pageInTab").ligerTab({
				height : 'auto',
				contextmenu : false,
				minIframeHeight : GET_minIframeHeight(),
				onAfterSelectTabItem : function(tabid) {
					currTab = tabid; //赋值是哪个Tab页面
					if (loadedTabs.indexOf(tabid) < 0) {
						loadedTabs.push(tabid);
						switch (tabid) {
						case "tabB":
							pageInTab.setTabItemSrc(tabid, "<%=path%>/bizflow/rskUsrAchLog/toMyAchievementsPage.do");
							break;
						}
					}
					;
					SetIframe_height();
				}
			});
	
			$.extend(true, pageInApp, {
				pageInTab : pageInTab
			});
		}
	</script>

</body>
</html>
